﻿using Microsoft.Playwright;
using Region.Spider;

public static class ILocatorExtensions
{
    public static async Task<string> GetAreaNameAsync(this ILocator locator)
    {
        var text = await locator.InnerTextAsync();
        return Tools.FormatName(text);
    }

    public static async Task<string> GetAreaCodeAsync(this ILocator locator, int len)
    {
        var text = await locator.InnerTextAsync();
        return Tools.FormatCode(text, len);
    }

    public static async Task<string> GetAreaCodeFromHrefAsync(this ILocator locator, int len)
    {
        var href = await locator.GetAttributeAsync("href");
        return Tools.GetCodeFromHref(href, len);
    }

    public static async Task<string> GetUrlFromHrefAsync(this ILocator locator)
    {
        var href = await locator.GetAttributeAsync("href");
        return $"{href}";
    }
}
